package com.example.crm.service;

import com.example.crm.entity.Business;
import com.example.crm.repository.BusinessRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service//标注是服务类
public class BusinessService {

    @Autowired//依赖注入，使其可以直接操作数据库business
    private BusinessRepository businessRepository;

    public List<Business> findAll() {

        return businessRepository.findAll();//在数据库找到所有插入的business并列出来
    }

    public Business save(Business business) {

        return businessRepository.save(business);//保存business
    }

    public Business getBusinessById(Integer id) {

        return businessRepository.findById(id).orElse(null);//根据id找business
    }

    public void deleteBusiness(Integer id) {

        businessRepository.deleteById(id);//根据id删除business
    }


}